/**
* All Rights Reserved , Copyright (C) 2023 , 青岛鼎信通讯股份有限公司
*
* MpmProjectChangeManagerInfoService
* 项目交接详情
*
* 修改纪录
* 2023-05-05 版本：1.0 houyuhang 创建。
* @version 版本：1.0
* @author 作者：houyuhang
* 创建日期：2023-05-05
*/
package com.topscomm.mpm.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import com.topscomm.basic.exception.ServiceException;
import com.topscomm.mpm.pojo.MpmProjectChangeManagerInfoEntity;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.tap.common.DatacodeCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.mpm.service.IMpmProjectChangeManagerInfoService;
import com.topscomm.mpm.service.impl.auto.MpmProjectChangeManagerInfoServiceAuto;

import java.util.List;
import java.util.Map;

@Service(value = "mpmProjectChangeManagerInfoService")
@Scope(value = "singleton")
public class MpmProjectChangeManagerInfoService extends MpmProjectChangeManagerInfoServiceAuto implements IMpmProjectChangeManagerInfoService {
    @Autowired
    private MpmProjectPolymerizationService mpmProjectPolymerizationService;
    /**
     * @author: houyuhang
     * @date: 2021-09-06
     * @param: mapRow
     * @param: datacodeCache
     * @description:重写setDispFields
     * @return: void
     * @modify:
     */
    @Override
    public void setDispFields(Map<String, Object> mapRow, DatacodeCache datacodeCache) {
        super.setDispFields(mapRow, datacodeCache);
        String temp;
        if (mapRow.get("projectlevel") != null) {
            temp = mapRow.get("projectlevel").toString();
            mapRow.put("dispprojectlevel", datacodeCache.getValueDynamic("MpmProjectLevel", temp, "code", "name"));
        }
        // 如果单据为审批不通过，项目状态显示立项不通过
        if (mapRow.get("projectstate") != null) {
            mapRow.put("dispprojectstate", mpmProjectPolymerizationService.getDispprojectstate(mapRow));
        }
    }
    /**
     * @author: houyuhang
     * @date: 2023-05-05
     * @description: 项目交接详情表保存
     * @modify:
     */
    public void insertChangeManagerInfo(long parentid, List<Map<String, Object>> infoList) {
        if (CollectionUtil.isEmpty(infoList)) {
            return;
        }
        // 删除原有项目交接详情内容
        this.deleteByWhere(" parentid = '" + parentid + "'");
        // 新增项目交接详情内容
        for (Map<String, Object> infoMap : infoList) {
            MpmProjectChangeManagerInfoEntity entity = new MpmProjectChangeManagerInfoEntity();
            entity.convertFromMap(infoMap);
            entity.setId(0L);
            entity.setParentid(parentid);
            this.insert(entity);
        }
    }
}
